---
# tasklist for setting up the mirrorlist app components
# create mirrormanager user
# create mirrormanager user
- name: add mirrormanager user - uid {{ mirrormanager_uid }}
  user: name=mirrormanager uid={{ mirrormanager_uid }} state=present home=/home/mirrormanager createhome=yes
  tags:
  - mirrorlist2

- name: make a /var/lib/mirrormanager dir for data
  file: dest=/var/lib/mirrormanager/ state=directory owner=mirrormanager group=mirrormanager mode=0755
  tags:
  - mirrorlist2

- name: install packages for mirrorlist
  yum: pkg={{ item }} state=present enablerepo=epel-testing
  with_items:
  - mirrormanager2-mirrorlist
  - python-IPy
  tags:
  - packages
  - mirrorlist2

- name: make sure mirrorlist-server is enabled (but not started yet in case we do not have pkl)
  service: name=mirrorlist-server enabled=yes
  tags:
  - mirrorlist2

# install mirrorlist-server.conf apache config
- name: mirrorlist-server apache conf
  template: src=mirrorlist-server.conf dest=/etc/httpd/conf.d/mirrorlist-server.conf
  notify:
  - restart apache
  tags:
  - config
  - mirrorlist2

# mirrormanager user ssh key(s)
- name: add authorized_keys for mirrormanager
  authorized_key: key="{{ item }}" user=mirrormanager state=present
  with_file:
  - mm-authorized_key
  tags:
  - mirrorlist2


# Three tasks for handling our (two) custom selinux modules.
- name: ensure a directory exists for our custom selinux module
  file: dest=/usr/share/mirrorlist2 state=directory
  tags:
  - mirrorlist2
  - selinux

- name: copy over our general mirrorlist2 selinux module
  copy: src=selinux/mirrorlist2.pp dest=/usr/share/mirrorlist2/mirrorlist2.pp
  register: ficgeneral_module
  tags:
  - mirrorlist2
  - selinux

#- name: check to see if its even installed yet
#  shell: semodule -l | grep mirrorlist2 | wc -l
#  register: ficgeneral_grep
#  always_run: true
#  changed_when: "'0' in ficgeneral_grep.stdout"
#  tags:
#  - mirrorlist2
#  - selinux

#- name: install our general mirrorlist2 selinux module
#  command: semodule -i /usr/share/mirrorlist2/mirrorlist2.pp
#  when: ficgeneral_module|changed or ficgeneral_grep|changed
#  tags:
#  - mirrorlist2
#  - selinux


- name: HOTFIX - increase the number of possible child processes and use threads
  copy: src="{{ files }}/hotfix/mirrorlist/mirrorlist_server.py" dest=/usr/share/mirrormanager2/mirrorlist_server.py
        owner=root group=root mode=0755
  tags:
  - hotfix

- name: make a /var/log/mirrormanager dir for logs
  file: dest=/var/log/mirrormanager/ state=directory owner=mirrormanager group=mirrormanager mode=0755
  tags:
  - mirrorlist2

- name: copy systemd service file in for mirrorlist-server
  copy: src=mirrorlist-server.service dest=/etc/systemd/system/mirrorlist-server.service
  notify:
  - reload systemd service files
  - restart mirrorlist-server
  tags:
  - mirrorlist2
